#!/usr/bin/env python
# -*- coding: utf-8 -*-

import functions

# Check if user directory exists, else create it.
functions.check_user_directory()

if not functions.check_config_file():
    functions.create_config_file()

elif functions.check_config_file():
    if functions.check_if_run() == True:
        user_x_action = functions.ask_for_x_tunnel()
        if user_x_action == True:
            functions.close_tunnel(functions.read_configuration("host"), functions.read_configuration("port"))
        else:
            functions.say_bye()
            exit()
    else:
        user_action = functions.ask_for_tunnel()
        if user_action == 0:
            functions.say_bye()
            exit()
        elif user_action == 1:
            open_tunnel = functions.open_tunnel(functions.read_configuration("host"), functions.read_configuration("port"), functions.read_configuration("user"))
            return_message = functions.tunnel_init_message(functions.check_if_run())
        elif user_action == 2:
            edit_config = functions.reedit_config()

